package org.example.project.bookstore.controller;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.example.bean.User;
import org.example.project.bookstore.service.UserService;
import org.example.util.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther:Liu
 * @Testname:UserController
 * @Date:2025/8/18 11:21
 */
@RestController
@RequestMapping("/new_user")
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("/login")
    JsonResult newlogin(User user) {
        return userService.login(user);
    }

    @PostMapping("/getUserName")
    JsonResult getUserName(HttpServletRequest request) {
        return userService.getUserName(request.getHeader("token"));
    }

    @GetMapping("/outlogin")
    JsonResult outlogin(HttpServletRequest request) {
        return userService.outLogin(request.getHeader("token"));
    }


    @PostMapping("/addUser")
    JsonResult addUser(User user) {
        return userService.saveUser(user);
    }
}
